#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
	string minWindow(string s, string t) {
		int n = s.size(), m = t.size();
		if (n < m || m == 0) return "";
		
		unordered_map<char, int> hash, hash1;
		for (char c : t) {
			hash[c]++;
		}
		
		int ans_l = 0, min_len = INT_MAX;
		int count = 0;
		
		for (int l = 0, r = 0; r < n; r++) {
			char in = s[r];
			
			hash1[in]++;
			if (hash1[in] <= hash[in]) {
				count++;
			}
			
			
			while (count == m) {
				if (r - l + 1 < min_len) {
					min_len = r - l + 1;
					ans_l = l;
				}
				
				char out = s[l];
				
				
				if (hash1[out] <= hash[out]) {
					count--;
				}
				hash1[out]--;
				l++;
			}
		}
		
		return (min_len == INT_MAX) ? "" : s.substr(ans_l, min_len);
	}
};
int main() 
{
	Solution sol;
	string s = "ADOBECODEBANC";
	string t = "ABC";
	cout << sol.minWindow(s, t) << endl; // 输出: "BANC"
	return 0;
}
